﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Atom.Utility;
using System.IO;

namespace MontiorReport
{
    static class Program
    {
        public static string HosName = "";
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new FrmMain());
            //Application.Run(new FrmMain());



            string path = System.Windows.Forms.Application.StartupPath + "\\Medlicense.ini";
            if (!File.Exists(path))
            {
                MessageBox.Show("没有授权文件，请联系软件制造商！");
                File.Create(path);
                return;
            }
            using (StreamReader sr = File.OpenText(path))
            {
                string input = string.Empty;
                if ((input = sr.ReadLine()) != null)
                {

                    try
                    {
                        //医院名称|开始时间|使用时间|CPU编号|网卡编号|其他
                        string[] str = EncryptDecrypt.Decrypt(input).Split('|');
                        string hosName = str[0];
                        DateTime dtBegin = Convert.ToDateTime(str[1]);
                        DateTime dtEnd = Convert.ToDateTime(str[2]);
                        string cpuID = str[3];
                        string mac = str[4];
                        string other = str[5];

                        //设置医院名称
                        HosName = hosName;

                        DateTime now = (DateTime.Now > dtBegin) ? DateTime.Now : dtBegin;

                        if (cpuID.Equals(EncryptDecrypt.GetCpuID()) && EncryptDecrypt.GetMacInfo().IndexOf(mac) > -1)
                        {
                            if (now <= dtEnd && now > dtBegin)
                            {
                                //启动主画面
                                Application.Run(new mycontext());
                            }
                            else
                            {
                                MessageBox.Show("产品使用已过期，请联系注册！");

                                Application.Run(new FrmRegist());
                            }
                        }
                        else
                        {
                            Application.Run(new FrmRegist());
                        }
                    }
                    catch
                    {

                        MessageBox.Show("不合法的授权文件，请联系软件制造商！");
                    }

                }
                else
                {
                    Application.Run(new FrmRegist());
                }

                sr.Close();
                sr.Dispose();
            }

        }
    }
}
